package com.apartment.own.controller;

import java.text.ParseException;
import java.util.List;

import com.apartment.own.request.subscribe.OwnOrderSubscribeQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.apartment.common.annotation.Log;
import com.apartment.common.core.controller.BaseController;
import com.apartment.common.core.domain.AjaxResult;
import com.apartment.common.enums.BusinessType;
import com.apartment.own.domain.OwnOrdSubscribe;
import com.apartment.own.service.IOwnOrdSubscribeService;
import com.apartment.common.utils.poi.ExcelUtil;
import com.apartment.common.core.page.TableDataInfo;

import javax.validation.Valid;

/**
 * 添加预约 业务员记录租客的预约看房的记录Controller
 *
 * @author @Dog_E
 * @date 2020-08-28
 */
@RestController
@RequestMapping("/own/subscribe")
@Api(value = "租客预约", tags = "租客预约")
public class OwnOrdSubscribeController extends BaseController
{
    @Autowired
    private IOwnOrdSubscribeService ownOrdSubscribeService;

    /**
     * 查询添加预约 业务员记录租客的预约看房的记录列表
     */
    //@PreAuthorize("@ss.hasPermi('own:subscribe:list')")
    @GetMapping("/list")
    @ApiOperation("查询所有预约")
    public TableDataInfo list(OwnOrderSubscribeQuery ownOrdSubscribe)
    {
        startPage();
        List<OwnOrdSubscribe> list = ownOrdSubscribeService.selectOwnOrdSubscribeList(ownOrdSubscribe);
        return getDataTable(list);
    }

    /**
     * 导出添加预约 业务员记录租客的预约看房的记录列表
     */
    @PreAuthorize("@ss.hasPermi('own:subscribe:export')")
    @Log(title = "添加预约 业务员记录租客的预约看房的记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OwnOrderSubscribeQuery ownOrdSubscribe)
    {
        List<OwnOrdSubscribe> list = ownOrdSubscribeService.selectOwnOrdSubscribeList(ownOrdSubscribe);
        ExcelUtil<OwnOrdSubscribe> util = new ExcelUtil<OwnOrdSubscribe>(OwnOrdSubscribe.class);
        return util.exportExcel(list, "subscribe");
    }

    /**
     * 获取预约 业务员记录租客的预约看房的记录详细信息
     */
    @ApiOperation("通过Id获取详细信息")
    @PreAuthorize("@ss.hasPermi('own:subscribe:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id")  String id)
    {
        return AjaxResult.success(ownOrdSubscribeService.selectOwnOrdSubscribeById(id));
    }

    /**
     * 新增添加预约 业务员记录租客的预约看房的记录
     */
    @PreAuthorize("@ss.hasPermi('own:subscribe:add')")
    @Log(title = "添加预约 业务员记录租客的预约看房的记录", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("添加预约")
    public AjaxResult add(@Valid @RequestBody OwnOrderSubscribeQuery ownOrdSubscribe)
    {
        return toAjax(ownOrdSubscribeService.insertOwnOrdSubscribe(ownOrdSubscribe));
    }

    /**
     * 修改添加预约 业务员记录租客的预约看房的记录
     */
    @PreAuthorize("@ss.hasPermi('own:subscribe:edit')")
    @Log(title = "添加预约 业务员记录租客的预约看房的记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OwnOrdSubscribe ownOrdSubscribe)
    {
        return toAjax(ownOrdSubscribeService.updateOwnOrdSubscribe(ownOrdSubscribe));
    }

    /**
     * 删除添加预约 业务员记录租客的预约看房的记录
     */
    @PreAuthorize("@ss.hasPermi('own:subscribe:remove')")
    @Log(title = "添加预约 业务员记录租客的预约看房的记录", businessType = BusinessType.DELETE)
    @ApiOperation("撤销预约,删除预约")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(ownOrdSubscribeService.deleteOwnOrdSubscribeByIds(ids));
    }
}
